package com.example.springboot1012.controller;

import com.example.springboot1012.mysqlclass.UserServerimpl;
import com.example.springboot1012.mysqlclass.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


//mySql
//https://www.jianshu.com/p/ca185e2b19fe
@Controller
public class UserController {
    @Autowired
    private UserServerimpl userServer;

    //获取
    @ResponseBody
    @RequestMapping("/username")
    public String GetUserName(){
        List<User> users =  userServer.getUserList();
        //return  users.get(users.size()-1).user_name;
        return  users.get(0).user_name;
    }

    //新增
    @ResponseBody
    @PostMapping("/adduser")
    public String addUser(User user)
    {
        String res = userServer.addUser(user);
        return res;
    }
}
